import json
import pprint

import requests
import execjs

with open('test2.js', 'r', encoding='utf-8') as f:
    js_code = f.read()
headers = {
    "accept": "text/plain, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "origin": "https://search.bidcenter.com.cn",
    "priority": "u=1, i",
    "referer": "https://search.bidcenter.com.cn/",
    "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
}
url = "https://interface.bidcenter.com.cn/search/GetSearchProHandler.ashx"
data = {
    "from": "6137",
    "guid": "a0c7933a-02e6-445e-a789-faefb8aae3c0",
    "location": "6138",
    "token": "",
    "keywords": "%e4%b8%ad%e5%a4%ae%e7%a9%ba%e8%b0%83",
    "mod": "0"
}
response = requests.post(url, headers=headers, data=data)

plaint_text = execjs.compile(js_code).call('get_data', response.text)
data = json.dumps(plaint_text,  indent=2, ensure_ascii=False)
result = json.loads(data)
print(data)
print(len(plaint_text["other2"]["listData"]))
